﻿package  
{
	
	/**
	* ...
	* @author DefaultUser (Tools -> Custom Arguments...)
	*/
	import flash.events.TimerEvent;
	import flash.display.Sprite;
	import Box2D.Common.Math.b2Vec2;
	public class Log extends Obstacle
	{
		
		private var logChoice:Number;
		
		private var deathAnim:String;
		private var velocity:Number = 0;
		public function Log(X:Number, Y:Number,animation:AnimatedSprite) 
		{
			super(X, Y);
			var explode:Animation = new Animation(9);
			var idle:Animation = new Animation(1);
				
				
			idle.FramesPerSecond = 15;
			explode.FramesPerSecond = 20;
				
			
			this._animation = animation;
			
			
			this.logChoice = Math.random() * 3;
			this.logChoice = Math.ceil(logChoice);
			
			if (logChoice == 1)
			{
				this._animation.Animations["log1"] = idle;
				this._animation.Animations["log1_break"] = explode;
				this._animation.CurrentAnimation = "log1";
				this.deathAnim = "log1_break";
			}
			if (logChoice == 2)
			{
				this._animation.Animations["log2"] = idle;
				this._animation.Animations["log2_break"] = explode;
				this._animation.CurrentAnimation = "log2";
				this.deathAnim = "log2_break";
			}
			if (logChoice == 3)
			{
				this._animation.Animations["log3"] = idle;
				this._animation.Animations["log3_break"] = explode;
				this._animation.CurrentAnimation = "log3";
				this.deathAnim = "log3_break";
			}
			

			
			this._animation.StartAnimation();
			this.addChild(_animation);
		}
		public override function Update():Boolean
		{
			
			
			this.y += velocity;
			velocity += 0.5;
			
			this.position.x =  this.x / 30;
			this.position.y = this.y / 30;
			
			//return true;
			return super.Update();
		}
		
		public override function Dispose():void
		{
			
			this._animation.CurrentAnimation = this.deathAnim;
			super.Dispose();
		
			
		
			
			Main.sound.play("log_break");
		}
		
	}
	
}